package service.impl;

import bean.SetBean;
import mapper.ISetMapper;
import org.apache.ibatis.session.SqlSession;
import service.ISetService;

import java.util.List;

public class SetServiceImpl extends BaseService implements ISetService {
    @Override
    public List<SetBean> findByRoomId(Integer roomId) {
        SqlSession session = this.getSession();
        ISetMapper mapper = session.getMapper(ISetMapper.class);
        List<SetBean> list = mapper.findByRoomId(roomId);
        session.close();
        return list;
    }

    @Override
    public void add(SetBean setBean, Integer roomId) {
        SqlSession session = this.getSession();
        ISetMapper mapper = session.getMapper(ISetMapper.class);
        mapper.add(setBean, roomId);
        session.commit();
        session.close();
    }

    @Override
    public void handle(Integer setId, Integer roomId) {
        SqlSession session = this.getSession();
        ISetMapper mapper = session.getMapper(ISetMapper.class);
        mapper.handle(setId, roomId);
        Integer unSettleNum = mapper.unSettleCount(roomId);
        if (unSettleNum == 0) {
            mapper.updateRoom(roomId);
        }
        session.commit();
        session.close();
    }
}
